package com.linghu.databasecase;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;

import androidx.annotation.Nullable;

/**
 * author : LingHu
 * e-mail : 1714873054@qq.com
 * date   : 2023/9/28 11:53
 * desc   :
 * version: 1.0
 */
public class DatabaseHelper extends SQLiteOpenHelper {

    private static final String TAG="DatabaseHelper";
    /**
     *
     * @param context
     */
    //初始化数据库数据
    public DatabaseHelper(@Nullable Context context) {
        super(context, Constants.DATABASE_NAME, null, Constants.VERSION_CODE);
    }


    /**
     * 第一次创建数据库时会执行它
     * @param db
     */
    @Override
    public void onCreate(SQLiteDatabase db) {
        //创建时的回调
        Log.d(TAG,"创建数据库");
        String sql=
                "create table "+Constants.TABLE_NAME+" (id Integer,name varchar,age Integer,salary Integer)";
        db.execSQL(sql);
    }

    /**
     * 升级数据库时的回调
     * @param
     * @param i
     * @param i1
     */
    @Override
    public void onUpgrade(SQLiteDatabase db, int i, int i1) {
        //升级数据库时的回调
        Log.d(TAG,"升级数据库");
    }
}
